package com.common.www.service.tabulation;


import org.springframework.boot.base.jpa.service.BaseLogicService;
import com.common.www.bean.entity.project.BiddingCompany;
import com.common.www.bean.entity.project.Project;
import com.common.www.bean.entity.tabulation.OuterSummary;
import com.common.www.repository.tabulation.OuterSummaryRepository;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

@Service
@Transactional
public class OuterSummaryService extends BaseLogicService<OuterSummary,Long> {
    @Autowired
    private OuterSummaryRepository repository;
    @Override
    public OuterSummaryRepository getRepository() {
        return repository;
    }

    /**
     * 标底：生成清单关联基础信息
     * @param project
     * @param jieDuan
     */
    public void saveCorrelationBd(Project project, Integer jieDuan,String fileName){
        OuterSummary outerSummary = null;
        if (jieDuan == 1){
            outerSummary = getRepository().getByConditionJieDuanOne(project.getId());
        }else if (jieDuan == 2){
            outerSummary = getRepository().getByConditionJieDuanSeven(project.getId());
        }
        if (outerSummary == null){
            outerSummary = new OuterSummary();
            outerSummary.setProject(project);
            outerSummary.setJieDuan(jieDuan);
            outerSummary.setCableCd(0.0);
            outerSummary.setFileName(fileName);
        }
        repository.save(outerSummary);
    }


    /**
     * 供应商清单：生成清单关联基础信息
     * @param biddingCompany
     * @param jieDuan
     */
    public void saveCorrelationGys(BiddingCompany biddingCompany, Integer jieDuan,String fileName){
        OuterSummary outerSummary = null;
        if (jieDuan != 1 && jieDuan != 2){
            outerSummary = repository.getByConditionJieDuanTemp(biddingCompany.getProject().getId(),biddingCompany.getId(),jieDuan);
        }
        if (outerSummary == null){
            outerSummary = new OuterSummary();
            outerSummary.setProject(biddingCompany.getProject());
            outerSummary.setBiddingCompany(biddingCompany);
            outerSummary.setJieDuan(jieDuan);
            outerSummary.setCableCd(0.0);
            outerSummary.setFileName(fileName);
        }
        repository.save(outerSummary);
    }


}
